package com.dreamcar.auction.managedbean;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;

import com.dreamcar.auction.ejb.ReverseAuctionFacadeLocal;
import com.dreamcar.auction.entity.CarModel;
import com.dreamcar.auction.entity.Component;
import com.dreamcar.auction.entity.DestinationMarket;
import com.dreamcar.auction.enums.ComponentEnum;

@ManagedBean(name="carComponentManager")
@SessionScoped
public class CarComponentManager {
	
	@EJB
	ReverseAuctionFacadeLocal reverseAuctionFacade;

	private List<SelectItem> lstDestinationMarket;
	private List<SelectItem> lstCarModel;
	private List<SelectItem> lstComponent;
	private List<SelectItem> lstCategoryComponent;
	
	private String dmActual;
	private String cmActual;
	private String cActual;
	private String catActual;
	
	
	
	public String getDmActual() {
		return dmActual;
	}
	public void setDmActual(String dmActual) {
		this.dmActual = dmActual;
	}
	public String getCmActual() {
		return cmActual;
	}
	public void setCmActual(String cmActual) {
		this.cmActual = cmActual;
	}
	public String getcActual() {
		return cActual;
	}
	public void setcActual(String cActual) {
		this.cActual = cActual;
	}
	public String getCatActual() {
		return catActual;
	}
	public void setCatActual(String catActual) {
		this.catActual = catActual;
	}

	public List<SelectItem> getLstDestinationMarket() {
		lstDestinationMarket = new ArrayList<SelectItem>();
		List<DestinationMarket> lst = reverseAuctionFacade.findAllDestinationMarket();
		for (DestinationMarket destinationMarket : lst) {
			lstDestinationMarket.add(new SelectItem(destinationMarket.getIdDestinationMarket(),destinationMarket.getDestination()));
		}
		return lstDestinationMarket;
	}
	
	public void getCarModelByDestinationMarket(){
		lstCarModel = new ArrayList<SelectItem>();
		List<CarModel> lst = reverseAuctionFacade.findCarModelByDestinationMarket(Integer.valueOf(dmActual));
		for (CarModel carModel : lst) {
			lstCarModel.add(new SelectItem(carModel.getIdCarModel(),carModel.getModel()));
		}
	}
	
	public List<SelectItem> getLstCarModel() {
		return lstCarModel;
	}
	
	public List<SelectItem> getLstCategory(){
		lstCategoryComponent = new ArrayList<SelectItem>();
		ComponentEnum[] components = ComponentEnum.values();
		for (ComponentEnum componentEnum : components) {
			lstCategoryComponent.add(new SelectItem(componentEnum.getComponent(), componentEnum.name()));
		}
		return lstCategoryComponent;
	}
	
	
	public void getCarComponentByCarModel(){
		if(catActual == null){
			return;
		}
		lstComponent = new ArrayList<SelectItem>();
		List<Component> lst = reverseAuctionFacade.findCarComponentByCarModel(Integer.valueOf(cmActual), catActual);
		for (Component component : lst) {
			lstComponent.add(new SelectItem(component.getIdComponent(), component.getDescription()));
		}
	}
	
	public List<SelectItem> getLstComponent() {
		getCarComponentByCarModel();
		return lstComponent;
	}
	
}
